package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.GradeBean;
import com.project.bean.RoleBean;
import com.project.service.IGradeService;
import com.project.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("role")
@RestController
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IGradeService gradeService;

    @RequestMapping("findAll")
    public List<RoleBean> findAll(){
        return roleService.findAll();
    }

    @RequestMapping("cutAll")
    public IPage<RoleBean> cutAll(int pageNO){
        return roleService.cutAll(pageNO);
    }

    @RequestMapping("findGrade")
    public List<GradeBean> findGrade(){
        return gradeService.findAll();
    }


    @RequestMapping("addRole")
    public String addRole(RoleBean role,int[] gradeArray){
        roleService.add(role,gradeArray);
        return "ok";
    }

    @RequestMapping("update")
    public String update(int roleId,int[] gradeArray){
        roleService.updateGrade(roleId,gradeArray);
        return "ok";
    }

    @RequestMapping("findById")
    public RoleBean findById(int id){
        return roleService.findById(id);
    }

}
